#include "EchoServer.h"
#include "Log.h"

#include <string>
#include <signal.h>
#include <thread>
INITIALIZE_EASYLOGGINGPP

EchoServer *echoserver;
//./为可执行程序所在的路径
LogHandler loghandler("./config/log.conf");

void stop(int sig)
{
    LOG(INFO) << "sig:" << sig;
    echoserver->stop();
    LOG(INFO) << "echoserver已停止。";
    // todo 为什么这行代码会阻塞？
    delete echoserver;
    LOG(INFO) << "delete echoserver。";
    exit(0);
}

int main(int argc, char **argv)
{
    if (argc != 3)
    {
        printf("usage: ./echoserver ip port\n");
        printf("example: ./echoserver 192.168.238.132 5000\n\n");
        return -1;
    }
    //捕获信号
    signal(SIGTERM, stop);
    signal(SIGINT, stop);

    echoserver = new EchoServer(argv[1], std::stoi(argv[2]), 3, 4);
    echoserver->start();
    
    return 0;
}